package cn.aloxc.tianya.reader;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Activity_test_dialog extends Activity{
	Button button1 = null;
	Button button2 = null;
	Button button3 = null;
	Button button4 = null;
	private static final int DIALOG1 = 1;
	private static final int DIALOG2 = 2;
	private static final int DIALOG4 = 4;
	private static final int DIALOG3 = 3;	
	OnClickListener listener_button1 = null;
	OnClickListener listener_button2 = null;
	OnClickListener listener_button3 = null;
	OnClickListener listener_button4 = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test_dialog);
		listener_button1 = new OnClickListener(){
			public void onClick(View v) {
				showDialog(DIALOG1);
			}};
		listener_button2 = new OnClickListener(){
			public void onClick(View v) {
				showDialog(DIALOG2);
			}};
		listener_button3 = new OnClickListener(){
			public void onClick(View v) {
				showDialog(DIALOG3);
			}};
		listener_button4 = new OnClickListener(){
			public void onClick(View v) {
				showDialog(DIALOG4);
			}};					
		button1 = (Button)findViewById(R.id.test_dialog_button1);
		button2 = (Button)findViewById(R.id.test_dialog_button2);
		button3 = (Button)findViewById(R.id.test_dialog_button3);
		button4 = (Button)findViewById(R.id.test_dialog_button4);
		button1.setOnClickListener(listener_button1);
		button2.setOnClickListener(listener_button2);
		button3.setOnClickListener(listener_button3);
		button4.setOnClickListener(listener_button4);
		
	}
	@Override
	protected Dialog onCreateDialog(int id) {
		switch(id) {
			case DIALOG1:
				return buildDialog1(Activity_test_dialog.this);
			case DIALOG2:
				return buildDialog2(Activity_test_dialog.this);
			case DIALOG3:
				return buildDialog3(Activity_test_dialog.this);
			case DIALOG4:
				return buildDialog4(Activity_test_dialog.this);
			default:
				break;
		}
		return super.onCreateDialog(id);
	}
	private Dialog buildDialog1(Context context) {
		AlertDialog.Builder builder = new Builder(context);
		builder.setIcon(R.drawable.yun);
		builder.setTitle(R.string.test_dialog_button1);
		builder.setPositiveButton(R.string.test_button_text_ok,new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface arg0, int arg1) {
				setTitle("你点击了对话框上的确定！");
			}
		});
		builder.setNegativeButton(R.string.test_button_text_cencel, new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialog, int which) {
				setTitle("你点击了对话框上的取消！");
			}});
		return builder.create();
	}
	private Dialog buildDialog3(Context context) {
		LayoutInflater flater = LayoutInflater.from(this);
		final View textEntryView = flater.inflate(R.layout.activity_test_dialog_register, null);
		AlertDialog.Builder builder = new Builder(context);
		builder.setIcon(R.drawable.yun);
		builder.setTitle(R.string.test_dialog_button3);
		builder.setView(textEntryView);
		builder.setPositiveButton(R.string.test_button_text_ok,new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface arg0, int arg1) {
				setTitle("你点击了对话框上的确定！");
			}
		});
		builder.setNegativeButton(R.string.test_button_text_cencel, new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialog, int which) {
				setTitle("你点击了对话框上的取消！");
			}});
		return builder.create();
	}
	private Dialog buildDialog4(Context context) {
		ProgressDialog dialog = new ProgressDialog(context);
		dialog.setTitle("正在下载歌曲");
		dialog.setMessage("请稍候……");
		return  dialog;
	}
	private Dialog buildDialog2(Context context) {
		AlertDialog.Builder builder = new Builder(context);
		builder.setIcon(R.drawable.png_ico);
		builder.setTitle(R.string.test_dialog_button2);
		builder.setMessage(R.string.test_button_text_msg);
		builder.setPositiveButton(R.string.test_button_text_ok,new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface arg0, int arg1) {
				setTitle("你点击了对话框上的确定！");
			}
		});
		builder.setNeutralButton(R.string.test_button_text_viewDetail,new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface arg0, int arg1) {
				setTitle("你点击了对话框上的查看详情！");
			}
		});
		builder.setNegativeButton(R.string.test_button_text_cencel, new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialog, int which) {
				setTitle("你点击了对话框上的取消！");
			}});
		return builder.create();
	}
}
